package com.fira.api.controller;

import com.fira.api.domain.dto.CourseDTO;
import com.fira.api.domain.dto.CourseMealDTO;
import com.fira.api.domain.dto.LoginDTO;
import com.fira.common.core.controller.BaseController;
import com.fira.common.core.domain.AjaxResult;
import com.fira.common.utils.StringUtils;
import com.fira.edu.domain.EduCourse;
import com.fira.edu.domain.EduCourseMeal;
import com.fira.edu.service.IEduCourseMealService;
import com.fira.edu.service.IEduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(value="课程信息接口",tags={"课程信息"})
@Controller
@RequestMapping("/api/course")
public class CourseController extends ApiController {
    private static final Logger log = LoggerFactory.getLogger(CourseController.class);
    @Autowired
    private IEduCourseService eduCourseService;
    @Autowired
    private IEduCourseMealService eduCourseMealService;

    @ApiOperation(value="查询课程列表",tags={"查询课程列表"},notes="")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult getCourseList(@ApiParam(name = "courseDTO", value = "课程查询入参") @Valid CourseDTO courseDTO, HttpServletRequest request){
        LoginDTO loginDTO = getLogin(request);
        String tenantId = loginDTO.getCurrentTenantId();
        if(StringUtils.isBlank(tenantId)){
            return AjaxResult.error("查询失败[当前用户不是租户]");
        }
        courseDTO.setTenantId(tenantId);
        EduCourse course = new EduCourse();
        BeanUtils.copyProperties(courseDTO,course);
        return AjaxResult.success("查询成功",eduCourseService.selectEduCourseList(course));
    }

    @ApiOperation(value="查询课程套餐列表",tags={"查询课程套餐列表"},notes="")
    @PostMapping("/mealList")
    @ResponseBody
    public AjaxResult getCourseMealList(@ApiParam(name = "courseMealDTO", value = "课程套餐查询入参") @RequestBody @Valid CourseMealDTO courseMealDTO){
        EduCourseMeal courseMeal = new EduCourseMeal();
        BeanUtils.copyProperties(courseMealDTO,courseMeal);
        return AjaxResult.success("查询成功",eduCourseMealService.selectEduCourseMealList(courseMeal));
    }
}
